package com.alon.spring01.common.config.redis;

import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @program: spring01
 * @description: redisson客户端
 * @author: yulongguang
 * @create: 2019-06-01 15:56
 **/
@Component
@Lazy(false)
public class RedissonManager {

    private static Config config = new Config();
    //声明redisso对象
    private static Redisson redisson = null;

    static {
//        config.useSingleServer().setAddress("127.0.0.1:6379");
        config.useSingleServer()
                // use "rediss://" for SSL connection
                .setAddress("redis://127.0.0.1:6379");
        //得到redisson对象
        redisson = (Redisson) Redisson.create(config);

    }

    public RedissonManager() {
    }

    //获取redisson对象的方法
    @PostConstruct
    public static Redisson getRedisson() {
        return redisson;
    }
}
